From afe801a3be7876408534f48b21e7e11a799ddf0d Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Tue, 17 Oct 2006 18:36:26 +0100 Subject: [PATCH] It's not correct to call endwin() if initscr() fails, and it crashes older libcurses implementations. Signed-off-by: John Levon --- tools/xenstat/xentop/xentop.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c index 271f4b2bf7..7d3ec59d2e 100644 --- a/tools/xenstat/xentop/xentop.c +++ b/tools/xenstat/xentop/xentop.c @@ -187,6 +187,8 @@ char prompt_val[PROMPT_VAL_LEN]; int prompt_val_len = 0; void (*prompt_complete_func)(char *); +static WINDOW *cwin; + /* * Function definitions */ @@ -223,7 +225,7 @@ static void version(void) /* Clean up any open resources */ static void cleanup(void) { - if(!isendwin()) + if(cwin != NULL && !isendwin()) endwin(); if(prev_node != NULL) xenstat_free_node(prev_node); @@ -236,7 +238,7 @@ static void cleanup(void) /* Display the given message and gracefully exit */ static void fail(const char *str) { - if(!isendwin()) + if(cwin != NULL && !isendwin()) endwin(); fprintf(stderr, str); exit(1); @@ -1029,7 +1031,7 @@ int main(int argc, char **argv) if (!batch) { /* Begin curses stuff */ - initscr(); + cwin = initscr(); start_color(); cbreak(); noecho(); -- 2.30.2